package com.mwh.yuantu.dao;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mwh.yuantu.dao.mapper.TypeFieldMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mwh.yuantu.entity.TypeFieldEntity;

/**
 * (TypeField)表数据库访问层
 *
 * @author maweihong
 * @since 2023-11-01 09:47:32
 */
@Service
public class TypeFieldDao extends ServiceImpl<TypeFieldMapper , TypeFieldEntity> {

    @Autowired
	private TypeFieldMapper typeFieldMapper;

    /**
     * 根据分类信息主键，查询该分类下的字段配置
     * @param typeId 分类信息主键
     * @return
     */
    public List<TypeFieldEntity> listByTypeId(String typeId) {
        return typeFieldMapper.listByTypeId(typeId);
    }

    /**
     * 判断在该分类中是否已包含此字段
     * @param typeId 分类信息主键
     * @param fieldId 字段主键
     * @return
     */
    public int countFieldByTypeIdAndFieldId(@Param("typeId") String typeId, @Param("fieldId") String fieldId) {
        return typeFieldMapper.countFieldByTypeIdAndFieldId(typeId , fieldId);
    }

    /**
     * 删除该分类下的所有字段配置
     * @param typeId 分类信息主键
     * @return
     */
    public int deleteByTypeId(String typeId) {
        return typeFieldMapper.deleteByTypeId(typeId);
    }

    /**
     * 批量插入分类信息下的字段配置
     * @param typeFieldList
     * @return
     */
    public int batchInsert(@Param("typeFieldList") List<TypeFieldEntity> typeFieldList) {
        return typeFieldMapper.batchInsert(typeFieldList);
    }

    /**
     * 检索指定字段是否必填
     * @param typeId 分类信息主键
     * @param varName 字段变量名
     * @return
     */
    public String selectIsRequired(@Param("typeId") String typeId, @Param("varName") String varName) {
        return typeFieldMapper.selectIsRequired(typeId , varName);
    }

    /**
     * 查询字段被使用的分类数量
     * @param fieldId 字段主键
     * @return
     */
    public int countByFieldId(String fieldId) {
        return typeFieldMapper.countByFieldId(fieldId);
    }

    /**
     * 根据分类信息主键，查询条数
     * @param typeId 分类信息主键
     * @return
     */
    public int countByTypeId(String typeId) {
        return typeFieldMapper.countByTypeId(typeId);
    }
}

